
// WebGUIDoc.h : interface of the CWebGUIDoc class
//


#pragma once


class CMainFrame ;

// this structure used to maintain the latest information about each node
struct SERVER_NODE
{
	CString strType ;
	CString strIP ;
	CString strCPU ;
	CString strMemUsed ;
	CString strMemFree ;
	CString strRequestCount ;
	CString strLastRequestTime ;
};
class CWebGUIDoc : public CDocument
{
protected: // create from serialization only
	CWebGUIDoc();
	DECLARE_DYNCREATE(CWebGUIDoc)

// Attributes
public:

	BOOL m_bConnected ;
	SYSTEMTIME m_stStartTime ;
	SYSTEMTIME m_stLastUpdate ;

	BOOL m_bRecording ;
	// Operations
public:

// Overrides
public:
	virtual BOOL OnNewDocument();
	virtual void Serialize(CArchive& ar);

	// UI upade flag
	BOOL m_bShouldUpdate ;
	
	// Init Winsock API
	BOOL InitWSA() ;   

	// Process new arrived packet from FM and detects if a nodes has been departs or a new node has joined the system
	void ProcessNewPacket();
	
	// Add new log to the LogViewer View
	void AddLog( CString strEventType , CString strDesciption ) ;
	
	// Refresh node list view 
	void RefreshNodeList();

	// obtains a pointer to the parent frame
	CMainFrame *GetFrame();

	// Send a request to Fault manager for the new packet
	BOOL SendRequest();

	// Get new packet from FM
	BOOL GetPacket();

	// calls when a change in connection happens
	void OnChangeConnection();

	// content of the latest packet string
	CString m_strLastPacket ;

	// IP and port address of FM connection
	CString m_strIP ;
	int m_nPort ;

	// read and decode the packet string to a structure of type SERVER_NODE
	void ReadPacket(CString strPacket);
// Implementation
public:
	virtual ~CWebGUIDoc();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

	CArray <SERVER_NODE,SERVER_NODE> m_aNodes ;
	CArray <SERVER_NODE,SERVER_NODE> m_aNodesNew ;
	HANDLE m_hNodeMutex ;
protected:

// Generated message map functions
protected:
	DECLARE_MESSAGE_MAP()
};


